program  STUDENTRECORD(INPUT,OUTPUT,FILENAME);
{$U+}
const
  maxstudents = 50;
type
   CODE=(A,S);
   date=record
     DT:1..31;
     MT:1..12;
     YR:1889..2200
    end;
   STUDENT = record
     Name: array [1..80] of char;
     Adrs: array [1..80] of char;
     Roll:INTEGER;
     Z:CODE
   end;
var
 stu:student;
 dat:date;
 GRADE:real;
 A1,B:array [1..50] of real;
 I,MARKS:INTEGER;
 FILEVAR:file of student;
 FILENAME:string[14];
 CHOICE1,X:char;
 NOFSTUDENTS:0..maxstudents;
 M1,M2,M3,M4,M5,M6:INTEGER;
 Z1,Z2,Z3,Z4,Z5:INTEGER;

PROCEDURE STREAM;
  begin
      WRITELN;
      WRITELN('PROCEDURE FOR SELECTION OF COURSE ');
      WRITELN;
      WRITELN('THE CHOICES ARE  ');
      WRITELN;
      WRITELN('   A -->  ARTS  ');
      WRITELN;
      WRITELN('   S -->  SCIENCE ');
      WRITELN;
      WRITELN('GIVE CHOICE OF COURSE ');
      WRITELN;
      READLN(X);
            X:=upcase(X);
            I:=I+1;
            case X of
               'A':begin
                     WRITELN;
                     WRITELN('-----------');
                     WRITELN('ARTS STREAM ');
                     WRITELN('-----------');
                     WRITELN;
                     WRITELN('SUBJECTS ARE ');
                     WRITELN;
                     WRITELN('ENG,MAR,HIN,HIS,GEOG,ECO ');
                     WRITELN;
                     WRITELN('GIVE MARKS OUT OF 100 ');
                     WRITELN;
                     WRITE('ENGLISH : ');
                     READLN(M1);
                     WRITE('MARATHI: ');
                     READLN(M2);
                     WRITE('HINDI: ');
                     READLN(M3);
                     WRITE('HISTORY:  ');
                     READLN(M4);
                     WRITE('GEOGRAPHY: ');
                     READLN(M5);
                     WRITE('ECONOMICS: ');
                     READLN(M6);
                     MARKS:=(M1+M2+M3+M4+M5+M6);
                     GRADE:=MARKS/6;
                     WRITELN;
                     WRITELN('% = ',GRADE);
                     WRITELN('GIVE PRECENTAGE ');
                     READLN(A1[I]);
                   end;
               'S':begin
                     WRITELN;
                     WRITELN('--------------');
                     WRITELN('SCIENCE STREAM ');
                     WRITELN('--------------');
                     WRITELN;
                     WRITELN('SUBJECTS ARE ');
                     WRITELN;
                     WRITELN('ENG,MATH,PHY,CHEM,BIO');
                     WRITELN;
                     WRITELN('GIVE MARKS OUT OF 100');
                     WRITELN;
                     WRITE('ENGLISH: ');
                     READLN(Z1);
                     WRITE('MATHS: ');
                     READLN(Z2);
                     WRITE('PHYSICS: ');
                     READLN(Z3);
                     WRITE('CHEMISTRY: ');
                     READLN(Z4);
                     WRITE('BIOLOGY: ');
                     READLN(Z5);
                     MARKS:=(Z1+Z2+Z3+Z4+Z5);
                     GRADE:=MARKS/5;
                     WRITELN;
                     WRITELN('% = ',GRADE );
                     WRITELN;
                     WRITELN('GIVE PERCENTAGE ');
                     READLN(B[I]);
                   end;{S}
             end;{CASE}
 end; {STREAM}

procedure ADDRECORDS;
 var
   Z:INTEGER;
 begin
 WRITELN;
 WRITELN('PROCEDURE FOR ADDITION FO RECORDS ');
 WRITELN;
   NOFSTUDENTS:=0;
   I:=0;
   WRITELN('CREATE WHICH FILE ?');
   READLN(FILENAME);
   ASSIGN(FILEVAR,FILENAME);
   REWRITE(FILEVAR);
   repeat
     if NOFSTUDENTS = maxstudents then
       begin
         WRITELN('CLASSROOM IS FULL ');
         WRITELN;
         WRITELN('NO NEW STUDENT CAN BE TAKEN ')
       end
     else
       begin
         WRITELN;
         WRITELN(' NEW RECORD ');
         WRITELN;
         NOFSTUDENTS:= NOFSTUDENTS + 1;
         with  stu do
          begin
           WRITE('ROLL NO  :  ');
           READLN(ROLL);
           if (ROLL <> 0) then
            begin
             WRITE('NAME : ');
             READLN(NAME);
             WRITE('ADDRESS : ');
             READLN(ADRS);
             WRITELN(' BIRTHDATE :  ');
               with dat do
                begin
                  WRITE('DATE: ');
                  READLN(DT);
                  WRITE('MONTH:  ');
                  READLN(MT);
                  WRITE('YEAR:  ');
                  READLN(YR);
                end;
             STREAM;
            end;
          end;
       end;
    WRITE(FILEVAR,STU);
    WRITELN;
    WRITE('GIVE 1 TO CONTINUE AND 0 TO STOP :    ');
    READLN(Z);
   until(Z=0);
   WRITELN;
   CLOSE(FILEVAR);
 end;{ADDRECORDS}

PROCEDURE TOPPER;
var
 CHOICE2:char;
 M:REAL;
begin
 WRITELN;
 WRITELN('PROCEDURE TO FIND TOPPER IN CLASS');
 WRITELN;
 WRITELN('  A --> TOPPER IN ARTS CLASS');
 WRITELN;
   WRITELN('  S--> TOPPER IN SCIENCE CLASS');
   WRITELN;
   WRITE('ENTER YOUR CHOICE -->  ');
   READLN(CHOICE2);
   WRITELN;
   CHOICE2:=upcase(CHOICE2);
   case CHOICE2 of
     'A':begin
            WRITELN('TO FIND TOPPER IN ARTS CLASS');
            WRITELN;
            M:=0;
            for I:=1 to NOFSTUDENTS do
            begin
             if A1[I] > M then
               M:=A1[I];
             WRITELN('TOPPER IN ARTS CLASS HAS',M,'MARKS');
            end;
         end;
       'S':begin
            WRITELN('TO FIND TOPPER IN SCIENCE CLASS');
            WRITELN;
            M:=0;
            for I:=1 to NOFSTUDENTS do
            begin
              if B[I] > M then
                M:=B[I];
              WRITELN('TOPPER IN SCIENCE CLASS HAS',M,'MARKS');
            end;
         end;
    end;
end;

PROCEDURE LISTRECORDS;
 begin
   WRITELN;
   WRITELN('PROCEDURE TO LIST THE RECORDS  ');
   WRITELN;
   WRITELN('GIVE NAME OF FILE TO BE OPENED ');
   READLN(FILENAME);
   ASSIGN(FILEVAR,FILENAME);
   {$I-}
    RESET(FILEVAR);
   {$I+}
       if (IORESULT <> 0) then
           WRITELN('FILE NOT FOUND ',IORESULT)
       else
        begin
         WRITELN('FILE OPENED ');
         WRITELN;
         repeat
           READ(FILEVAR,STU);
             with stu do
               begin
                 WRITELN('=================================================');
                 WRITELN('      PROBLEM ON VARIANT RECORDS                 ');
                 WRITELN('=================================================');
                 WRITELN('NAME >> ', NAME);
                 WRITELN('-------------------------------------------------');
                 WRITELN('ADDRESS >> ',ADRS);
                 WRITELN('-------------------------------------------------');
                 WRITELN('ROLL NO >> ',ROLL);
                 WRITELN;
                 WRITE('BIRTHDATE >> ');
                 with dat do
                  begin
                   WRITELN(DT,'/ ',MT,'/ ',YR );
                   WRITELN('-------------------------------------------------');
                  end;
                 WRITELN('CODE >> ',X);
                 repeat until KEYPRESSED;
                 CLRSCR;
                 if (X = 'A') then
                   begin
                     WRITELN('----------------------');
                     WRITELN('SUBJECT   |     MARKS ');
                     WRITELN('----------------------');
                     WRITE('ENGLISH   | ');
                     WRITELN(M1);
                     WRITE('MARATHI   | ');
                     WRITELN(M2);
                     WRITE('HINDI     | ');
                     WRITELN(M3);
                     WRITE('HISTORY   | ');
                     WRITELN(M4);
                     WRITE('GEOGRAPHY | ');
                     WRITELN(M5);
                     WRITE('ECONOMICS | ');
                     WRITELN(M6);
                     WRITELN('----------------------');
                     WRITELN('TOTAL     | ',MARKS);
                     WRITELN('----------------------');
                     WRITELN('PERCENTAGE| ',GRADE);
                     WRITELN('----------------------');
                     repeat  until  KEYPRESSED;
                     CLRSCR;
                     TOPPER;
                     if (M1 OR M2 OR M3 OR M4 OR M5 OR M6 < 35 ) then
                       begin
                       WRITELN;
                         WRITELN('STUDENT HAS FAILED ');
                         WRITELN;
                         WRITELN('STUDENT HAS NO GRADE ');
                       end
                     else
                       begin
                         WRITELN;
                         WRITELN('STUDENT HAS PASSED');
                         WRITELN;
                         if (GRADE >= 60) then
                           WRITELN('STUDENT HAS GRADE -->>  I');
                         if (GRADE >=45) and (GRADE <60) then
                           WRITELN('STUDENT HAS GRADE -->>  II');
                         if (GRADE >=35) and (GRADE <45) then
                           WRITELN('STUDENT HAS GRADE -->>  III');
                       end;
                 repeat  until  KEYPRESSED;
                 CLRSCR;
               end;
              if (X = 'S') then
               begin
                 WRITELN('---------------------------');
                 WRITELN('SUBJECT   | MARKS ');
                 WRITELN('---------------------------');
                 WRITE('ENGLISH   | ');
                 WRITELN(Z1);
                 WRITE('MATHS     | ');
                 WRITELN(Z2);
                 WRITE('PHYSICS   | ');
                 WRITELN(Z3);
                 WRITE('CHEMISTRY | ');
                 WRITELN(Z4);
                 WRITE('BIOLOGY   | ');
                 WRITELN(Z5);
                 WRITELN('---------------------------');
                 WRITELN('TOTAL     | ',MARKS);
                 WRITELN('---------------------------');
                 WRITELN('PERCENTAGE| ',GRADE);
                 WRITELN('---------------------------');
                 repeat  until  KEYPRESSED;
                 CLRSCR;
                 TOPPER;
                 WRITELN;
                 if (Z1 OR Z2 OR Z3 OR Z4 OR Z5 < 35 ) then
                   begin
                     WRITELN('STUDENT HAS FAILED ');
                     WRITELN;
                     WRITELN('STUDENT HAS NO GRADE ');
                   end;
               end
              else
                 begin
                   WRITELN('STUDENT HAS PASSED');
                   WRITELN;
                   if (GRADE >= 60) then
                     WRITELN('STUDENT HAS GRADE -->> I');
                   if (GRADE >=45) and (GRADE <60) then
                     WRITELN('STUDENT HAS GRADE -->> II');
                   if (GRADE >=35) and (GRADE <45) then
                     WRITELN('STUDENT HAS GRADE -->> III');
                 end;
                 repeat  until  KEYPRESSED;
                 CLRSCR;
                end;
         until (eof(FILEVAR));
        end;
   CLOSE (FILEVAR);
end;

begin
  clrscr;
  WRITELN('PROGRAM FOR STUDENT RECORD ,GRADE AND MARKS');
  WRITELN;
  WRITELN;
  repeat
   WRITELN('THE CHOICES ARE ');
   WRITELN;
   WRITELN('  A --> ADDITION OF RECORDS TO FILE ');
   WRITELN;
   WRITELN('  L --> LISTING THE ADDED RECORDS  ');
   WRITELN;
   WRITELN('  Q --> QUITTING THE FILE  ');
   WRITELN;
   WRITE('ENTER YOUR CHOICE -->   ');
   READLN(CHOICE1);
   WRITELN;
   CHOICE1:=upcase(CHOICE1);
   repeat until  KEYPRESSED;
   CLRSCR;
   case CHOICE1 of
     'A':ADDRECORDS;
     'L':LISTRECORDS;
     'Q': begin
            WRITELN('===========================');
            WRITELN;
            WRITELN('    RETURNING TO TURBO     ');
            WRITELN;
            WRITELN('===========================');
            DELAY(3000);
          end
    end;
  until (CHOICE1 = 'Q');
end.
